package com.shell.governor.modules.service.impl;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.shell.governor.modules.dao.PubAttTmplDao;
import com.shell.governor.modules.po.PubAttTmpl;
import com.shell.governor.modules.service.PubAttTmplService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PubAttTmplServiceImpl extends PersistentServiceImpl<PubAttTmpl> implements PubAttTmplService {
	private String defaultGroup = "PT_0";
	@Autowired
	private PubAttTmplDao pubAttTmplDao;

	public PubAttTmpl selectTmplByGpAndType(String grpId, String tmplType) {
		if (StringUtil.emptyAndNull(tmplType)) {
			return null;
		}
		if (StringUtil.emptyAndNull(grpId)) {
			grpId = this.defaultGroup;
		}
		List<PubAttTmpl> tmpls = this.pubAttTmplDao.selectTmplByGpAndType(grpId, tmplType, "1");
		if ((tmpls != null) && (tmpls.size() > 0)) {
			return (PubAttTmpl) tmpls.get(0);
		}
		List<PubAttTmpl> ptTmpl = this.pubAttTmplDao.selectTmplByGpAndType(this.defaultGroup, tmplType, "1");
		if ((ptTmpl != null) && (ptTmpl.size() > 0)) {
			return (PubAttTmpl) ptTmpl.get(0);
		}
		return null;
	}
}
